import java.util.InputMismatchException;
import java.util.Scanner;



class Student {
    public String name = "zhangsan";

    @Override
    protected Object clone() throws CloneNotSupportedException ,NullPointerException{
        return super.clone();
    }
}
public class Test {


    public static void main22(String[] args) {
        try {
            func7();
        }catch (ArrayIndexOutOfBoundsException e) {
            e.printStackTrace();
        }
    }

    public static void func7() {
        try{
            int[] arr = {1,2,3};
            System.out.println(arr[5]);//数组越界访问异常
        }
        catch (NullPointerException e){
            e.printStackTrace();
            System.out.println("子类在前");
        }finally {
            System.out.println("finally被执行了哦！");
        }

    }
    public static void main14(String[] args) {
        //int ret = func6();
       // System.out.println("接收的返回值"+ret);
    }
    public static void main13(String[] args) {
        try(Scanner scanner = new Scanner(System.in)){
            int a = scanner.nextInt();

        }
        catch (NullPointerException e){
            e.printStackTrace();
            System.out.println("子类在前");
        }catch (InputMismatchException e) {
            e.printStackTrace();
        } finally {
            System.out.println("finally被执行了哦！");
        }
        System.out.println("该句是否被执行");
    }
    public static void main12(String[] args) {

        try(Scanner scanner = new Scanner(System.in)){
            int a = scanner.nextInt();
        }
        catch (NullPointerException e){
            System.out.println("子类在前");
        }catch (RuntimeException e) {
            System.out.println("父类在后");
        }finally {
            System.out.println("finally被执行了哦！");
        }
        System.out.println("666");
    }

    public static void main11(String[] args) {
        try{
            int[] arr = {1,2,3};
            System.out.println(arr[10]);
        }
        catch (NullPointerException e){
            System.out.println("子类在前");
        }catch (RuntimeException e) {
            System.out.println("父类在后");
        }
    }
    public static void main10(String[] args) {
        try{
            int[] arr = {1,2,3};
            System.out.println(arr[10]);
        }catch (Exception e) {
            e.printStackTrace();
            System.out.println("成功捕获到异常");
        }
        System.out.println("后续代码可被执行！");
    }
    public static void main9(String[] args) {
        try{
            int[] arr = {1,2,3};
            System.out.println(arr[10]);
        }catch (NullPointerException e) {
            e.printStackTrace();
            System.out.println("成功捕获到空指针异常");
        }catch(ArrayIndexOutOfBoundsException e) {
            e.printStackTrace();
            System.out.println("捕获到了数组越界异常");
        }
        System.out.println("后续代码可被执行！");
    }
    public static void main8(String[] args) {
        try{
            int[] arr = {1,2,3};
            System.out.println(arr[10]);//数组越界异常
        }catch (NullPointerException |ArrayIndexOutOfBoundsException e) {
            e.printStackTrace();
            System.out.println("成功捕获到空指针异常 | 数组越界异常");
        }
        System.out.println("后续代码可被执行！");
    }
    public static void main7(String[] args) {
        try{
            int[] arr = null;
            System.out.println(arr.length);
            //异常后面的代码
            System.out.println("你看我会被打印吗？");
        }catch (NullPointerException e) {
            e.printStackTrace();//打印异常（栈说上面的一些信息）
            System.out.println("成功捕获到异常");
        }
        System.out.println("后续代码可被执行！");
    }

    public static void func(){
        int[] arr = null;
        System.out.println(arr.length);
    }
    public static void main6(String[] args) {
        try{
            func();
            System.out.println("666");
        }catch (NullPointerException e) {
            e.printStackTrace();//打印异常
            System.out.println("处理NullPointerException异常成功！");
        }
        System.out.println("处理完异常可以继续走完下面的代码！");
    }

    public static void main5(String[] args) throws CloneNotSupportedException {
        Student student1 = new Student();
        Student student2 = (Student)student1.clone();
    }

    public static void func(int[] arr) {
        if(arr == null) {
            throw new NullPointerException("这是自己抛出的空指针异常");
            //System.out.println("异常后面不能有代码");
        }
    }
    public static void main4(String[] args) {
        func(null);
    }

    public static void main3(String[] args) {
        //空指针异常
        System.out.println("在异常发生前，是否会打印这句话");

        int[] arr = null;//此时arr为一个空引用
        System.out.println(arr[10]);
        System.out.println("检验这句话是否被打印");
    }
    public static void main2(String[] args) {
        //数组越界异常
        int[] arr = {1,2,3,4,5};
        System.out.println(arr[6]);
    }
    public static void main1(String[] args) {
        //算术异常
        System.out.println(10/0);
        System.out.println("检验这句话是否被打印");
    }

}
